Skip to content

Conversation

@guybedford
Copy link
Collaborator

@guybedford guybedford commented Oct 4, 2025

The import attributes specification is now part of ECMA-262. This rebases the spec to handle the new module request record and import attribute record functionality in module resolution.

In addition, I've also integrated a simple proposal for import attributes integration along the lines discussed in #42.

The design is to allow a ?... querystring on the export name to indicate the attributes, using standard URL query param semantics and referencing the URL spec for this exactly. This then fully encodes the import attributes grammar.

Effectively then, "./foo.bin" "default?type=bytes" can be used to import an immutable array buffer for arbitrary external data.

Supporting bytes, CSS and JSON imports natively for Wasm can be simply implemented this way.

This does change the meaning of ? in export names - but these are not currently commonly used in JS (I don't think I've ever seen a import { "?" as foo } from 'bar'). So it seems like this doesn't conflict with other uses since we have the source phase opt-out for other interpretations anyway not the instance phase. But we could add additional disambiguation by prefixing the export name with wasm-js: or wasm: if we wanted to have a stricter scheme here. Perhaps wasm-js://default/with?type=bytes, although it seems like it might be overkill too.

Copy link
Collaborator

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct from the point of view of properly integrating with ECMA-262.

I don't love the proposed "syntax", but I don't have better suggestions.

@eqrion
Copy link
Contributor

eqrion commented Nov 13, 2025

@guybedford How confident are we that the import attribute syntax won't grow beyond the capabilities of URL query params?

I'm a little mixed on this, because while it'd be nice to not have a semantic gap here, taking on fully-correct URL parsing is challenging. AFAIK, SpiderMonkey doesn't have a URL parser in it.

@nicolo-ribaudo
Copy link
Collaborator

nicolo-ribaudo commented Nov 13, 2025

There are at least some desires to start supporting booleans in import attributes other than strings. At some point there was some discussion about allowing arbitrary JSON (for the builtins option of WebAssembly.compile when importing Wasm from JS), but we ended up with a comma-separated string.

AFAIK, SpiderMonkey doesn't have a URL parser in it.

Resolving module specifiers when dealing with JS already requires URL parsing, because they are URLs. SpiderMonkey calls into Geko for it (in Firefox).

And Geko has more than one URL parser :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants